<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.prime.com.tr/ui"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html">

<ui:composition template="templates/pageTemplate.xhtml">
	<ui:define name="content">
		<h2>#{msgs['title.registers']}</h2>
		<p:fieldset legend="Отправка CSV" toggleable="true" toggleSpeed="500" id="csvForm" collapsed="true" rendered="#{facesContext.externalContext.isUserInRole('csvInput')}">		
		<form method="post" action="upload" enctype="multipart/form-data">
			<input type="file" name="file" />
			<input type="submit" value="#{msgs['action.send_csv']}"/>
		</form>
		<h:outputLink value="importedFiles.jsf" style="padding-left: 20px">
				<h:outputText value="На страницу отправленных файлов" style="font-size: 12px" />
			</h:outputLink>
		</p:fieldset>
		<br />
		<h:form>
			<p:fieldset legend="#{msgs['title.filter']}" toggleable="true"
				toggleSpeed="500" id="filterForm">
				<h:outputText value="#{msgs['data.identifier']}:" />
				<p:inputText value="#{registerTable.filterId}" />
				<br />
				<h:outputText value="#{msgs['data.born_date']}:" />
				<p:calendar showOn="button" value="#{registerTable.filterDate}"
					pattern="dd.MM.yyyy" />
				<br />
				<h:outputText value="#{msgs['data.status']}:" />
				<h:selectOneMenu id="filterStatus"
					value="#{registerTable.filterStatus}">
					<f:selectItem itemValue="" itemLabel="#{msgs['data.any']}" />
					<f:selectItems value="#{registerTable.registerStatuses}"
						var="status" itemValue="#{status}" itemLabel="#{status}" />
				</h:selectOneMenu>
				<br />
				<p:commandButton value="#{msgs['action.apply']}"
					update="registersList"
					actionListener="#{registerTable.applyFilter}" />
				<p:commandButton value="#{msgs['action.reset']}"
					update="filterForm, registersList"
					actionListener="#{registerTable.resetFilter}" />
			</p:fieldset>
			<br />
			<p:dataTable var="register" value="#{registerTable.registers}"
				paginator="true" rows="10" lazy="true"
				paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
				rowsPerPageTemplate="5,10,15" id="registersList"
				emptyMessage="Реестры не найдены">

				<f:facet name="header">
					<strong>#{msgs['title.registers']}</strong>
				</f:facet>
				<p:column headerText="#{msgs['data.identifier']}"
					sortBy="#{register.id}" style="width:150px">
					<h:outputText value="#{register.id}" />
				</p:column>
				<!-- Born date column -->

				<p:column sortBy="#{register.creationDate}"
					headerText="#{msgs['data.creation_date']}" style="width:150px">
					<h:outputText value="#{register.creationDate}">
						<f:convertDateTime pattern="dd.MM.yyyy" />
					</h:outputText>
				</p:column>
				<!-- last name column -->

				<p:column headerText="#{msgs['data.status']}"
					sortBy="#{register.status}" style="width:150px">
					<h:outputText value="#{register.status}" />
				</p:column>

				<p:column headerText="#{msgs['action.options']}" style="width:40px">
					<h:outputLink value="enteringRCTasks.jsf"
						rendered="#{register.status == 'DRAFT' and facesContext.externalContext.isUserInRole('manualInput')}">
						<f:param name="registerId" value="#{register.id}" />
						<h:outputText value="#{msgs['action.details']}" />
					</h:outputLink>
					<h:outputLink value="protocol.jsf"
						rendered="#{register.status == 'SCHEDULED'}">
						<f:param name="registerId" value="#{register.id}" />
						<h:outputText value="#{msgs['action.protocol']}" />
					</h:outputLink>
					<h:outputLink value="protocol.jsf"
						rendered="#{register.status == 'PROCESSED_SUCCESSFULLY'}">
						<f:param name="registerId" value="#{register.id}" />
						<h:outputText value="#{msgs['action.protocol']}" />
					</h:outputLink>
					<h:outputLink value="complete.jsf"
						rendered="#{register.status == 'PROCESSED_WITH_ERRORS' and facesContext.externalContext.isUserInRole('completeInput')}">
						<f:param name="registerId" value="#{register.id}" />
						<h:outputText value="#{msgs['action.edit']}" />
					</h:outputLink>
				</p:column>
				<!-- Edit row -->
			</p:dataTable>
			<p:commandButton value="#{msgs['action.add_register']}"
				action="#{registerTable.addRegister}" rendered="#{facesContext.externalContext.isUserInRole('manualInput')}"/>				
		</h:form>
	</ui:define>
</ui:composition>
</html>
